<?php
/**
*
* @package AJAX userinfo
* @version $Id: ajax_user.php, V0.1.3 2008-08-26 01:08:23 tas2580 $
* @copyright (c) 2007 SEO phpBB http://www.phpbb-seo.de
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

define('IN_PHPBB', true);
$phpbb_root_path = '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin(false);
$user->setup();

$ajax_userid =  request_var('userid', 0);

// Select some userdata from DB
$sql = 'SELECT
		username,
		user_regdate,
		user_posts,
		user_from,
		user_lastvisit,
		user_avatar,
		user_avatar_type,
		user_avatar_width,
		user_avatar_height,
		user_colour,
		user_website,
		user_rank
	FROM ' . USERS_TABLE . ' 
	WHERE user_id = '. (int) $ajax_userid;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);

$row['user_from'] = ($row['user_from']) ? $row['user_from'] : 'N/A';
$row['user_website'] = ($row['user_website']) ? $row['user_website'] : 'N/A';

// Get the Avatar
$phpbb_root_path = generate_board_url() . '/';
$theme_path = "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme';
$avatar = get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'], $row['user_avatar_height']);
$avatar = ($avatar) ? $avatar : '<img src="' . $theme_path . '/images/no_avatar.gif" alt="Avatar" />';

// Get rank
$rank_title = $rank_img = $rank_img_src = '';
get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
$rank_title = ($rank_title) ? $rank_title : 'N/A';

// Get username with usercolor
$username = get_username_string('full', $ajax_userid, $row['username'], $row['user_colour'], $row['username']);

// Send XML File
echo header('Content-Type: text/xml; charset=utf-8');
echo '<' . '?xml version="1.0" encoding="UTF-8"?' . '>';
echo '<userdata>';
echo '<username><![CDATA[' . $username . ']]></username>';
echo '<regdate><![CDATA[' . $user->format_date($row['user_regdate']) . ']]></regdate>';
echo '<posts><![CDATA[' . $row['user_posts'] . ']]></posts>';
echo '<from><![CDATA[' . $row['user_from'] . ']]></from>';
echo '<lastvisit><![CDATA[' . $user->format_date($row['user_lastvisit']) . ']]></lastvisit>';
echo '<website><![CDATA[' . $row['user_website'] . ']]></website>';
echo '<avatar><![CDATA[' . $avatar . ']]></avatar>';
echo '<rank><![CDATA[' . $rank_title . ']]></rank>';
echo'</userdata>';

$db->sql_freeresult($result);

?>